package com.example.eduservice.controller.front;

import com.example.common.commonsutils.R;
import com.example.common.vo.CourseInfoVO;
import com.example.eduservice.entity.frontvo.CourseDetailInfoVO;
import com.example.eduservice.entity.frontvo.CourseFrontIndexVO;
import com.example.eduservice.entity.vo.ChapterVO;
import com.example.eduservice.service.EduChapterService;
import com.example.eduservice.service.EduCourseService;
import com.example.eduservice.service.EduVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:tjf
 * @Description:
 */
@RestController
@RequestMapping("/eduservice/course/front")
@Tag(name = "前端课程控制器")
public class CourseFrontController {
    @Resource
    private EduCourseService courseService;
    @Resource
    private EduChapterService chapterService;
    @Operation(description = "条件查询课程列表带分页")
    @PostMapping("/page/{current}/{size}")
    public R queryFrontCourseListByConditionForPage(@PathVariable("current") Integer current,
                                               @PathVariable("size") Integer size,
                                               @RequestBody(required = false) CourseFrontIndexVO courseQuery){
        Map<String,Object> resultMap = courseService.queryFrontCourseListByConditionForPage(current, size, courseQuery);

        return R.ok().data((HashMap<String, Object>) resultMap);
    }
    @Operation(description = "根据id，查询课程的详细信息-课程信息、课程简介、教师信息等")
    @GetMapping("/detail/{id}")
    public R queryCourseDetailInfoById(@PathVariable("id") String id){
        // 查询课程的详细信息
        CourseDetailInfoVO courseInfo = courseService.queryCourseDetailInfoById(id);

        // 查询该课程的章节信息
        List<ChapterVO> chapterVOS = chapterService.queryChapterByCourseId(id);
        return R.ok().data("courseInfo", courseInfo).data("chapterVOS", chapterVOS);
    }
    @Operation(description = "为课程订单提供课程信息")
    @GetMapping("/order/{id}")
    public CourseInfoVO queryCourseInfoForOrderById(@PathVariable("id") String id){
        CourseInfoVO courseInfoVO = courseService.queryCourseInfoForOrder(id);
        return courseInfoVO;
    }
}
